﻿using System;
using System.Web;
using TheOutfield.UmbExt.IE9Extensions.Filters;
using umbraco;

namespace TheOutfield.UmbExt.IE9Extensions
{
    public class IE9ExtensionsModule : IHttpModule
    {
        #region IHttpModule Members

        public void Dispose()
        { }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);  
        }

        protected void context_BeginRequest(object sender, EventArgs e)
        {
            var app = sender as HttpApplication;
            if(app != null)
            {
                if(app.Request.Path.ToLower() == GlobalSettings.Path.Replace("~/", app.Request.ApplicationPath) +"/")
                    app.Response.Redirect(GlobalSettings.Path.Replace("~/", app.Request.ApplicationPath) + "/umbraco.aspx", true);
                else if (app.Request.Path.ToLower() == GlobalSettings.Path.Replace("~/", app.Request.ApplicationPath) + "/umbraco.aspx")
                    app.Response.Filter = new IE9ExtensionsFilter(app.Response.Filter);   
            }
        }

        #endregion
    }
}
